#include<iostream>
using namespace std;
struct TreeNode {
	int val;
	TreeNode* left;
	TreeNode* right;
	TreeNode() : val(0), left(nullptr), right(nullptr) {}
	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
	TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

class Solution {
public:
	TreeNode* flipTree(TreeNode* root) {
		if (!root)return nullptr;
		TreeNode* left = flipTree(root->left);
		TreeNode* right = flipTree(root->right);
		TreeNode* tmp = nullptr;
		tmp = left;
		root->left = right;
		root->right = left;
		return root;
	}
};